<?php


namespace app\api\controller\audit;


use app\api\controller\Api;
use app\common\audit\model\AuditComment;
use app\common\audit\validate\AuditCommentValidate;
use think\db\exception\DbException;

class Comment extends Api
{
    public function create()
    {
        $post = $this->request->post();
        $user = $this->request->user;

        $validate = new AuditCommentValidate();
        if (!$validate->check($post)) {
            return error([], $validate->getError());
        }

        $post['user_id'] = $user['id'];
        $model = new AuditComment();
        try {
            $model->save($post);
        } catch (DbException $e) {
            return error([], $e->getMessage());
        }
        return success([], "评论成功");
    }
}